//
//  UIImageView+FK.m
//  FKLibraryExample
//
//  Created by frank on 15/11/11.
//  Copyright © 2015年 zmosa. All rights reserved.
//

#import "UIImageView+FK.h"

@implementation UIImageView (FK)

- (void)setSharpCornerChatWithPoint:(CGPoint)point
{
    // 开启图形上下文
    UIGraphicsBeginImageContext(self.frame.size);
    // 取得上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 等有时间了再完善
}


/** 加载模型里面的二维码和频次信息 */
- (void)fk_imageWith:(NSString *)urlStr
{
    // 先判断缓存中是否有图片信息
    [[[SDWebImageManager sharedManager] imageCache] containsImageForKey:urlStr cacheType:SDImageCacheTypeAll completion:^(SDImageCacheType containsCacheType) {
        if (containsCacheType == SDImageCacheTypeNone) { // 缓存中没有就去下载
            NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
            NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr]];
            NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                UIImage *image = [UIImage imageWithData:data];
                [[[SDWebImageManager sharedManager] imageCache] storeImage:image imageData:data forKey:urlStr cacheType:SDImageCacheTypeAll completion:^{
                    NSLog(@"缓存成功");
                    [self sd_setImageWithURL:[NSURL URLWithString:urlStr]];
                }];
            }];
            [task resume];
        } else{
            [self sd_setImageWithURL:[NSURL URLWithString:urlStr]];
        }
    }];
    
}

@end
